<?php
include('setup.php');
$hostname_logon = 'localhost';      //Database server LOCATION
    $database_logon = 'wwwmsc_newcareer';       //Database NAME
    $username_logon = 'wwwmsc';       //Database USERNAME
    $password_logon = 'Slpnxhe}bX4h';       //Database PASSWORD
	$database_connection = mysql_connect($hostname_logon,$username_logon,$password_logon) or die("couldnt connect with mysql");
	$database_selection = mysql_select_db($database_logon,$database_connection);
	mysql_query( "SET NAMES utf8", $database_connection );
        mysql_query( "SET CHARACTER SET utf8", $database_selection );
// πέρνουμε τα πεδία από τη φόρμα μας και τα βάζουμε σε μεταβλητές
$ad_id = $_POST["ad_id"];
$ad_title = $_POST['ad_title'];
$ad_desc = $_POST['ad_desc'];
$ad_code = $_POST['ad_code'];
$ad_type = $_POST['ad_type'];
$ad_email = $_POST['ad_email'];
$ad_locid = $_POST['ad_locid'];
$ad_catid = $_POST['ad_catid'];
$ad_salary = $_POST['ad_salary'];
$ad_salary = $_POST['ad_salary'];
$user_autocomplete = $_POST['autocomplete'];

		$loc_country =$_POST["country"];
		$loc_locality =$_POST["locality"];
		$loc_route =$_POST["route"];
		$loc_postal_code =$_POST["postal_code"];
		$loc_administrative_area_level_1 =$_POST["administrative_area_level_1"];
		$loc_street_number =$_POST["street_number"];
	$insert_location_query = "insert into `LOCATION` set
								`loc_country`	=	'$loc_country'
							,	`loc_locality`	=	'$loc_locality'
							,	`loc_route`	=	'$loc_route'
							,	`loc_postal_code`	=	'$loc_postal_code'
							,	`loc_administrative_area_level_1`	=	'$loc_administrative_area_level_1'
							,	`loc_street_number`	=	'$loc_street_number'	";
	$insert_location_result	=	mysql_query($insert_location_query) or die(mysql_error());
	$ad_locid = mysql_insert_id();

	$category_select_query = "select cat_id from CATEGORIES WHERE `cat_desc` = '$ad_catid' limit 1";
	$category_select_result = mysql_query($category_select_query) or die(mysql_error());
	$category_select_id = mysql_result($category_select_result,0);
	if(!($category_select_id > 0))
	{
		$insert_category_query = "insert into CATEGORIES set `cat_desc` = '$ad_catid'";
		$insert_category_result = mysql_query($insert_category_query) or die(mysql_error());
		$inserted_category_id = mysql_insert_id();
	}
	else
	{
		$inserted_category_id = $category_select_id;
	}
// δημιουργία αντικειμένου setup
$setup = new setup();


// τρέχω το query μου για insert
$setup->qry("update ADS set 
ad_title = '".$ad_title."',
ad_desc = '".$ad_desc."',
ad_code = '".$ad_code."',
ad_type = '".$ad_type."',
ad_email = '".$ad_email."',
ad_locid = '".$ad_locid."',
ad_catid = '".$inserted_category_id."',
ad_salary = '".$ad_salary."',
ad_userid = '".$_SESSION['userid']."',
user_autocomplete = '".$user_autocomplete."' where `ad_id` = '$ad_id' limit 1");

// αν δεν με βγάλει κάποιο error τότε είναι επιτυχημένη η εγγραφή
if($error != "Error")
{
	header( "Location: ../portal.php?action=showAds&ad_id=$ad_id");
}
else
{
	header( "Location: ../portal.php?action=showAds&ad_id=$ad_id");
}

?>